function searchBy(name) {
	switch(name) {
		case "baidu":
			url = "https://www.baidu.com/s?wd=";
			break;
		case "google":
			url = "https://www.google.com/search?q=";
			break;
		case "googleM":
			url = "http://ohhhh.club/?q=";
			break;
	}
}

window.onload = function() {
	document.getElementById("mainSearch").oninput = function() {
		var swd = encodeURIComponent(document.getElementById("mainSearch").value);
		$.ajax({
			type:'GET',
			url:'https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su',
			dataType:'jsonp',
			data:{
				wd:swd,
				json:1,
				p:3,
				cb:'putSearchResults'
			}
		});
	}
}

function putSearchResults(result) {
	var q = result.q;
	var s = result.s;
	if (s.length > 0) {
		for (var i = 0; i <= s.length - 1; i++) {
			var tag = document.createElement("li");
			var text = document.createTextNode(s[i]);
			tag.appendChild(text);
			document.getElementById("sug-overflow").appendChild(tag);
		}
		document.getElementById("sug-overflow").style.display = "inline-block";
	} else {
		document.getElementById("sug-overflow").style.display = "none";
	}
}


function bdFanyi(query,from,to) {
	from = from || "auto";
	to = to || "zh";
	query = encodeURIComponent(query) || false;
	if (!query) return false;

	var token = "073324c918423f7c975d1edbd262e4b3",
		gtk = "320305.131321201";
	function a(r, o) {
	    for (var t = 0; t < o.length - 2; t += 3) {
	        var a = o.charAt(t + 2);
	        a = a >= "a" ? a.charCodeAt(0) - 87 : Number(a),
	        a = "+" === o.charAt(t + 1) ? r >>> a: r << a,
	        r = "+" === o.charAt(t) ? r + a & 4294967295 : r ^ a
	    }
	    return r
	}
	var C = null;
	var sign = function(r, _gtk) {
	    var o = r.length;
	    o > 30 && (r = "" + r.substr(0, 10) + r.substr(Math.floor(o / 2) - 5, 10) + r.substring(r.length, r.length - 10));
	    var t = void 0,
	    t = null !== C ? C: (C = _gtk || "") || "";
	    for (var e = t.split("."), h = Number(e[0]) || 0, i = Number(e[1]) || 0, d = [], f = 0, g = 0; g < r.length; g++) {
	        var m = r.charCodeAt(g);
	        128 > m ? d[f++] = m: (2048 > m ? d[f++] = m >> 6 | 192 : (55296 === (64512 & m) && g + 1 < r.length && 56320 === (64512 & r.charCodeAt(g + 1)) ? (m = 65536 + ((1023 & m) << 10) + (1023 & r.charCodeAt(++g)), d[f++] = m >> 18 | 240, d[f++] = m >> 12 & 63 | 128) : d[f++] = m >> 12 | 224, d[f++] = m >> 6 & 63 | 128), d[f++] = 63 & m | 128)
	    }
	    for (var S = h,
	    u = "+-a^+6",
	    l = "+-3^+b+-f",
	    s = 0; s < d.length; s++) S += d[s],
	    S = a(S, u);

	    return S = a(S, l),
	    S ^= i,
	    0 > S && (S = (2147483647 & S) + 2147483648),
	    S %= 1e6,
	    S.toString() + "." + (S ^ h)
	}

	$.ajax({
		url: "http://fanyi.baidu.com/v2transapi",
		type: "POST",
		dataType: "json",
		data: {
			from: from,
			to: to,
			query: query,
			simple_means_flag: 3,
			sign: sign(query, gtk),
			token: token
		},
		cache: !1,
		success: function(result) {
			console.log(result);
		}
	});
}